//package com.example.e_comm.vehicle.controller;
//
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.example.vehicle.dto.PageQueryDTO;
//import com.example.vehicle.dto.VehicleDTO;
//import com.example.vehicle.dto.VehicleReportDTO;
//import com.example.vehicle.entity.Vehicle;
//import com.example.vehicle.service.VehicleService;
//import jakarta.validation.Valid;
//import lombok.RequiredArgsConstructor;
//import org.springframework.beans.BeanUtils;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//import java.util.stream.Collectors;
//
//@RestController
//@RequestMapping("/api/vehicle")
//@RequiredArgsConstructor
//public class VehicleController {
//
//    private final VehicleService vehicleService;
//
//    private static final String[] STATUS_DESC = {"离线", "在线", "行驶中", "充电中"};
//
//    @PostMapping("/report")
//    public ResponseEntity<Void> reportVehicleStatus(@Valid @RequestBody VehicleReportDTO reportDTO) {
//        vehicleService.reportVehicleStatus(reportDTO);
//        return ResponseEntity.ok().build();
//    }
//
//    @GetMapping("/{vin}")
//    public ResponseEntity<VehicleDTO> getVehicleByVin(@PathVariable String vin) {
//        Vehicle vehicle = vehicleService.getVehicleByVin(vin);
//        if (vehicle == null) {
//            return ResponseEntity.notFound().build();
//        }
//        return ResponseEntity.ok(convertToDTO(vehicle));
//    }
//
//    @GetMapping("/list")
//    public ResponseEntity<IPage<VehicleDTO>> getVehicleList(@Valid PageQueryDTO queryDTO) {
//        IPage<Vehicle> vehiclePage = vehicleService.getVehiclePage(queryDTO);
//        IPage<VehicleDTO> dtoPage = vehiclePage.convert(this::convertToDTO);
//        return ResponseEntity.ok(dtoPage);
//    }
//
//    @GetMapping("/online")
//    public ResponseEntity<List<VehicleDTO>> getOnlineVehicles() {
//        List<Vehicle> vehicles = vehicleService.getOnlineVehicles();
//        List<VehicleDTO> dtos = vehicles.stream()
//                .map(this::convertToDTO)
//                .collect(Collectors.toList());
//        return ResponseEntity.ok(dtos);
//    }
//
//    @DeleteMapping("/{vin}")
//    public ResponseEntity<Void> deleteVehicle(@PathVariable String vin) {
//        vehicleService.deleteVehicleByVin(vin);
//        return ResponseEntity.ok().build();
//    }
//
//    private VehicleDTO convertToDTO(Vehicle vehicle) {
//        VehicleDTO dto = new VehicleDTO();
//        BeanUtils.copyProperties(vehicle, dto);
//        if (vehicle.getStatus() != null && vehicle.getStatus() >= 0 && vehicle.getStatus() < STATUS_DESC.length) {
//            dto.setStatusDesc(STATUS_DESC[vehicle.getStatus()]);
//        }
//        return dto;
//    }
//}